import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  { // 一级路由布局容器
    path: '/',
    component: () => import('@/views/Layout.vue'),
    children: [
      {
        path: '',
        component: () => import('@/views/home')
      },
      {
        path: '/category/:id',
        component: () => import('@/views/category/index')
      },
      {
        path: '/category/sub/:id',
        component: () => import('@/views/category/sub')
      },
      {
        path: '/product/:id',
        component: () => import('@/views/goods/index.vue')
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  // 每次切换路由都滚动到页面顶部
  scrollBehavior () {
    return { left: 0, top: 0 } // vue 2.0 通过{x,y}
    // vue 3.0 通过{left,top}
  }
})

export default router
